#push: first element has got the smallest priority
#pop   return the smallest element

import heapq

class Item:
    def __init__(self, name):
        self.name = name
    def __repr__(self):
        return 'Item({!r})'.format(self.name)

#TypeError: unorderable types: Item() > Item()
a = (1, Item("abc"))
b = (1, Item("abc"))

#print (a>b)

a = (1, Item("abc"))
b = (2, Item("abc"))

#False
print (a>b)
#True
print (a<b)

class PriorityQueue:
    def __init__ (self):
        self._queue  = []
        self._index  = 0

    def push(self, item, priority):
        heapq.heappush(self._queue, (-priority, self._index, item))
        self._index += 1

    def pop(self):
        #-1 iteration throw tuple, return Item
        return heapq.heappop(self._queue)[-1]

q = PriorityQueue()
q.push(Item("foo"), 1)
q.push(Item("bR"),  2)
q.push(Item("bR"),  0)
print (q._queue)
print (q.pop())
